package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全功能
     * @param keyword
     * @return
     */

    // http://localhost/api/search/albumInfo/completeSuggest/%E4%B8%89
    @Operation(summary = "自动补全功能")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }



    /**
     * 查询频道页数数据
     * @param category1Id
     * @return
     */
    //http://localhost/api/search/albumInfo/channel/1
    @Operation(summary = "查询频道页数数据")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable Long category1Id) {
      //调用服务层
        List<Map<String, Object>> mapList =  searchService.channel(category1Id);
        return Result.ok(mapList);
    }
    /**
     * 全文检索
     */
    @Operation(summary = "全文检索")
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    /**
     * 专辑批量上架
     * @return
     */
    @Operation(summary = "专辑批量上架")
    @GetMapping("/batchUpperAlubm")
    public Result batchUpperAlubm(ServletRequest servletRequest) {
        //调用服务层
        for (int i = 1; i <= 1500; i++) {
            searchService.upperAlbum((long) i);
        }
        return Result.ok();
    }

    /**
     * 专辑上架
     */
    @Operation(summary = "专辑上架")
    @GetMapping("upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        //调用服务层
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * 专辑上架
     */
    @Operation(summary = "专辑下架")
    @GetMapping("lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        //调用服务层
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /**
     * 更新排行榜
     */
    @Operation(summary = "更新排行榜")
    @GetMapping("updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        //调用服务层
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
    /**
     * 获取排行榜
     */
    @Operation(summary = "获取排行榜")
    @GetMapping("findRankingList/{category1Id}/{dimension}")
    public Result findRankingList(@PathVariable Long category1Id,@PathVariable String dimension){
        List<AlbumInfoIndex> albumInfoIndexList = searchService.findRankingList(category1Id,dimension);
        return Result.ok(albumInfoIndexList);
    }

}

